package com.wanxi.servlet.nav;

import com.alibaba.fastjson.JSONObject;
import com.wanxi.dto.ResultDto;
import com.wanxi.model.NavModel;
import com.wanxi.service.Impl.NavServiceImpl;
import com.wanxi.service.NavService;
import com.wanxi.util.Tool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Li
 * @Date 2023/5/7 13:15
 */
@WebServlet("/back/UpdateNav")
public class UpdateNavServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //乱码解决
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        //接收前端值
        String id = req.getParameter("id");
        String navName = req.getParameter("navName");
        String navHref = req.getParameter("navHref");
        String enable = req.getParameter("enable");
        String remark = req.getParameter("remark");
        //封装model
        NavModel navModel = NavModel.builder()
                .id(Tool.nullToInt(id))
                .navName(Tool.nullToStr(navName))
                .navHref(Tool.nullToStr(navHref))
                .enable(Tool.nullToInt(enable))
                .remark(Tool.nullToStr(remark))
                .build();
        //调用service层
        NavService navService = new NavServiceImpl();
        ResultDto resultDto = navService.update(navModel);
        //返回数据
        resp.getWriter().println(JSONObject.toJSONString(resultDto));

    }
}
